/*
* 1videoConference -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, Adiance Technologies Pvt. Ltd.
*
* Hardik Sanghvi <hardik.sanghvi @adiance.com>
*
* See http://www.1videoconference.org for more information about
* the 1videoConference project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using _videoConference.BAL;
using System.Net.Mail;

namespace _videoConference
{
    public partial class CreateMeeting : System.Windows.Controls.UserControl,IDisposable
    {
        int value = 0;
        IAddPage ia = new IAddPage();
        System.Data.DataSet ds = new System.Data.DataSet();
        System.Data.DataSet dsuser = new System.Data.DataSet();
        System.Data.DataSet dscountry = new System.Data.DataSet();
        System.Data.DataSet dsstate = new System.Data.DataSet();
        System.Data.DataSet dsguest = new System.Data.DataSet();
        System.Data.DataSet dsmeeting = new System.Data.DataSet();
        ComboBoxItem a;
        string accId;
        string hosturl;
        private bool disposed = false;
      
        public CreateMeeting()
        {
            try
            {
                InitializeComponent();
                lblUserInfo.Content = "Please Enter your Details:";
                lblFName.Content = "First Name:";
                lblLName.Content = "Last Name:";
                lblCity.Content = "City:";
                lblState.Content = "State:";
                lblCountry.Content = "Country:";
                lblPincode.Content = "Pin Code:";
                lblPhone.Content = "Phone:";
                lblFax.Content = "Fax:";
                lblEMail.Content = "Conference EMail";
                lblPassword.Content = "Conference Password:";
                lblMeetingName.Content = "Meeting Name:";
                lblMeetingDate.Content = "Date of Meeting:";
                lblDateFormate.Content = "(MM/DD/YYYY)";
                lblMeetingStartTime.Content = "Meeting Start Time";
                lblMeetingEndTime.Content = "Meeting End Time:";
                lblTimeZone.Content = "Based on EST Time Zone";
                lblPartiInvite.Content = "Participants To Invite:";
                lblFirstGuestEMail.Content = "Guest EMail:";
                lblFirstGuestName.Content = "First Name:";
                lblSecondGuestEMail.Content = "Guest EMail:";
                lblSecondGuestName.Content = "First Name:";
                lblThiredGuestEMail.Content = "Guest EMail:";
                lblThiredGuestName.Content = "First Name:";
                lblFourthGuestEMail.Content = "Guest EMail:";
                lblFourthGuestName.Content = "First Name:";
                lblFifthGuestEMail.Content = "Guest EMail:";
                lblFifthGuestName.Content = "First Name:";
                lblSixthGuestEMail.Content = "Guest EMail:";
                lblSixthGuestName.Content = "First Name:";
                lblValidate.Content = "";
                txtFName.Text = "";
                txtLName.Text = "";
                txtCity.Text = "";
                txtPinCode.Text = "";
                txtPhone.Text = "";
                txtFax.Text = "";
                txtEMail.Text = "";
                txtPassword.Password = "";
                txtMeetingName.Text = "";
                txtMeetingDate.Text = "";
                btnCancel.Click += new RoutedEventHandler(btnCancel_Click);

                dscountry = ia.getcountry();
                if (dscountry != null && dscountry.Tables.Count > 0 && dscountry.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i <= dscountry.Tables[0].Rows.Count - 1; i++)
                    {
                        try
                        {
                            a = new ComboBoxItem();
                            a.Content = dscountry.Tables[0].Rows[i][1].ToString();
                            a.Tag = dscountry.Tables[0].Rows[i][0].ToString();
                            a.Background = Brushes.Black;
                            a.Foreground = Brushes.White;
                            txtCountry.Items.Add(a);
                        }
                        catch (Exception exp)
                        {
                            exp.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--CreateMeeting()--:----:--");
                            clsUtility.LogException = exp;
                            //MessageBox.Show(exp.Message.ToString());
                        }
                    }
                }
                dsstate = ia.getstate("1=1");
                if (dsstate != null && dsstate.Tables.Count > 0 && dsstate.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i <= dsstate.Tables[0].Rows.Count - 1; i++)
                    {
                        a = new ComboBoxItem();
                        a.Content = dsstate.Tables[0].Rows[i][1].ToString();
                        a.Tag = dsstate.Tables[0].Rows[i][0].ToString();
                        a.Background = Brushes.Black;
                        a.Foreground = Brushes.White;
                        txtState.Items.Add(a);
                    }
                }

                txtFirstGuestEMail.Text = "";
                txtFirstGuestName.Text = "";
                txtSecondGuestEMail.Text = "";
                txtSecondGuestName.Text = "";
                txtThiredGuestEMail.Text = "";
                txtThiredGuestName.Text = "";
                txtFourthGuestEMail.Text = "";
                txtFourthGuestName.Text = "";
                txtFifthGuestEMail.Text = "";
                txtFifthGuestName.Text = "";
                txtSixthGuestEMail.Text = "";
                txtSixthGuestName.Text = "";


                for (int m = 1; m <= 24; m++)
                {
                    ComboBoxItem cbi = new ComboBoxItem();
                    ComboBoxItem cbi1 = new ComboBoxItem();
                    if (m < 10)
                    {
                        cbi.Content = "0" + m.ToString();
                        cbi.Background = Brushes.Black;
                        cbi.Foreground = Brushes.White;
                        CmbMeetingStart.Items.Add(cbi);
                        cbi1.Content = "0" + m.ToString();
                        cbi1.Background = Brushes.Black;
                        cbi1.Foreground = Brushes.White;
                        CmbMeetingEnd.Items.Add(cbi1);
                    }
                    else if (m >= 10 && m < 24)
                    {
                        cbi.Content = m.ToString();
                        cbi.Background = Brushes.Black;
                        cbi.Foreground = Brushes.White;
                        CmbMeetingStart.Items.Add(cbi);
                        cbi1.Content = m.ToString();
                        cbi1.Background = Brushes.Black;
                        cbi1.Foreground = Brushes.White;
                        CmbMeetingEnd.Items.Add(cbi1);
                    }
                }

                for (int min = 0; min <= 59; min++)
                {
                    ComboBoxItem cbimin = new ComboBoxItem();
                    ComboBoxItem cbi1min = new ComboBoxItem();
                    if (min < 10)
                    {
                        cbimin.Content = "0" + min.ToString();
                        cbimin.Background = Brushes.Black;
                        cbimin.Foreground = Brushes.White;
                        cmbMinStart.Items.Add(cbimin);
                        cbi1min.Content = "0" + min.ToString();
                        cbi1min.Background = Brushes.Black;
                        cbi1min.Foreground = Brushes.White;
                        cmbMinEnd.Items.Add(cbi1min);
                    }
                    else if (min >= 10 && min < 60)
                    {

                        cbimin.Content = min.ToString();
                        cbimin.Background = Brushes.Black;
                        cbimin.Foreground = Brushes.White;
                        cmbMinStart.Items.Add(cbimin);
                        cbi1min.Content = min.ToString();
                        cbi1min.Background = Brushes.Black;
                        cbi1min.Foreground = Brushes.White;
                        cmbMinEnd.Items.Add(cbi1min);
                    }
                }
                btnSubmit.Content = "Submit";
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--InitializeComponent()--:----:--");
                clsUtility.LogException = ex;
                //MessageBox.Show("Create Meeting--:--Create Meetin.xaml.cs--:-- InitializeComponent ---" + ex.Message); 
            }

            try
            {
                if (UserInfo.crtmeeting != "")
                {
                    ds = ia.meetingsel(UserInfo.crtmeeting);
                    txtMeetingName.Text = ds.Tables[0].Rows[0][0].ToString();
                    txtMeetingDate.Text = ds.Tables[0].Rows[0][1].ToString();

                    for (int i = 0; i < CmbMeetingStart.Items.Count; i++)
                    {
                        if (ds.Tables[0].Rows[0][2].ToString() == CmbMeetingStart.Items[i].ToString())
                        {
                            CmbMeetingStart.SelectedIndex = i;
                            break;
                        }
                    }
                    for (int i = 0; i < CmbMeetingEnd.Items.Count; i++)
                    {
                        if (ds.Tables[0].Rows[0][3].ToString() == CmbMeetingEnd.Items[i].ToString())
                        {
                            CmbMeetingEnd.SelectedIndex = i;
                            break;
                        }
                    }

                    accId = ds.Tables[0].Rows[0][4].ToString();
                    dsguest = ia.fetchguestemailname(UserInfo.crtmeeting);

                    txtFirstGuestEMail.Text = "";
                    txtFirstGuestName.Text = "";

                    txtSecondGuestEMail.Text = "";
                    txtSecondGuestName.Text = "";

                    txtThiredGuestEMail.Text = "";
                    txtThiredGuestName.Text = "";

                    txtFourthGuestEMail.Text = "";
                    txtFourthGuestName.Text = "";

                    txtFifthGuestEMail.Text = "";
                    txtFifthGuestName.Text = "";

                    txtSixthGuestEMail.Text = "";
                    txtSixthGuestName.Text = "";


                    txtFirstGuestEMail.Text = dsguest.Tables[0].Rows[0][0].ToString();
                    txtFirstGuestName.Text = dsguest.Tables[0].Rows[0][1].ToString();

                    txtSecondGuestEMail.Text = dsguest.Tables[0].Rows[1][0].ToString();
                    txtSecondGuestName.Text = dsguest.Tables[0].Rows[1][1].ToString();

                    txtThiredGuestEMail.Text = dsguest.Tables[0].Rows[2][0].ToString();
                    txtThiredGuestName.Text = dsguest.Tables[0].Rows[2][1].ToString();

                    txtFourthGuestEMail.Text = dsguest.Tables[0].Rows[3][0].ToString();
                    txtFourthGuestName.Text = dsguest.Tables[0].Rows[3][1].ToString();

                    txtFifthGuestName.Text = dsguest.Tables[0].Rows[4][0].ToString();
                    txtFifthGuestName.Text = dsguest.Tables[0].Rows[4][1].ToString();

                    txtSixthGuestEMail.Text = dsguest.Tables[0].Rows[5][0].ToString();
                    txtSixthGuestName.Text = dsguest.Tables[0].Rows[5][1].ToString();

                    dsuser = ia.userreg(ds.Tables[0].Rows[0][4].ToString());

                    txtFName.Text = dsuser.Tables[0].Rows[0][1].ToString();
                    txtLName.Text = dsuser.Tables[0].Rows[0][2].ToString();
                    txtPhone.Text = dsuser.Tables[0].Rows[0][3].ToString();
                    txtPinCode.Text = dsuser.Tables[0].Rows[0][4].ToString();
                    txtEMail.Text = dsuser.Tables[0].Rows[0][5].ToString();
                    txtPassword.Password = dsuser.Tables[0].Rows[0][6].ToString();
                    txtFax.Text = dsuser.Tables[0].Rows[0][7].ToString();
                    txtCity.Text = dsuser.Tables[0].Rows[0][8].ToString();

                    for (int i = 0; i < txtCountry.Items.Count; i++)
                    {
                        if (dsuser.Tables[0].Rows[0][9].ToString() == ((ComboBoxItem)txtCountry.Items[i]).Tag.ToString())
                        {
                            txtCountry.SelectedIndex = i;
                            break;
                        }
                    }
                    for (int i = 0; i < txtState.Items.Count; i++)
                    {
                        if (dsuser.Tables[0].Rows[0][10].ToString() == ((ComboBoxItem)txtState.Items[i]).Tag.ToString())
                        {
                            txtState.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)            
            {
                ex.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--Entering Into Meeting()--:----:--");
                clsUtility.LogException = ex;
                //MessageBox.Show("Create Meeting--:--Create Meetin.xaml.cs--:-- Entering IntoMeeting ---" + ex.Message); 
            }
        }

        void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ((Canvas)((Grid)((InkCanvas)((InkCanvas)this.Parent).Parent).Parent).FindName("cnvMain")).IsEnabled = true;
                ((Menu)((Grid)((InkCanvas)((InkCanvas)this.Parent).Parent).Parent).FindName("mnu")).IsEnabled = true;
                ((InkCanvas)this.Parent).Children.Remove(this);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--btnCancel_click()--:----:--");
                clsUtility.LogException = ex;
                //MessageBox.Show("create Meeting--:--Create Meeting.xaml.cs--:-- btnCancel_Click ---" + ex.Message); 
            }
        }

        void txtCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                txtState.Items.Clear();
                dsstate = ia.getstate("CountryId=" + ((ComboBoxItem)txtCountry.SelectedItem).Tag.ToString());

                for (int i = 0; i <= dsstate.Tables[0].Rows.Count - 1; i++)
                {
                    a = new ComboBoxItem();
                    a.Content = dsstate.Tables[0].Rows[i][1].ToString();
                    a.Tag = dsstate.Tables[0].Rows[i][0].ToString();
                    a.Background = Brushes.Black;
                    a.Foreground = Brushes.White;
                    txtState.Items.Add(a);
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--txtCountry_SelectionChange()--:----:--");
                clsUtility.LogException = ex;
                //MessageBox.Show("Create Meeting--:-- Create Meeting.xaml.cs--:-- txtCountry_SelectionChange" + ex.Message); 
            }
        }

        void Enter(object sender, EventArgs e)
        {
            try
            {
                value = ia.datecompare(txtMeetingDate.Text, CmbMeetingStart.SelectionBoxItem.ToString() + ":" + cmbMinStart.SelectionBoxItem.ToString());
                if (value == 0)
                {
                    lblValidate.Content = "Enter Date Or Time Should be Greater than Currenmt DateTime";
                    return;
                }
                if (txtFName.Text == "")
                {
                    lblValidate.Content = "Please Enter Your Name";
                    return;
                }
                else if (txtEMail.Text == "")
                {
                    lblValidate.Content = "Please Enter Valid Email Address";
                    return;
                }

                else if (txtMeetingDate.Text == "")
                {
                    lblValidate.Content = "Please Enetr Meeting Date";
                    return;
                }

                else if (Convert.ToDateTime(CmbMeetingStart.SelectionBoxItem.ToString() + ":" + cmbMinStart.SelectionBoxItem.ToString()) > Convert.ToDateTime(CmbMeetingEnd.SelectionBoxItem.ToString() + ":" + cmbMinEnd.SelectionBoxItem.ToString()))
                {
                    lblValidate.Content = "End time should be greater then Start time ";
                    return;
                }


                #region Check Users EMail Addresses and First Name

                else if (txtEMail.Text.ToString().Contains("@") && txtEMail.Text.ToString().Contains("."))
                {
                    if (txtFirstGuestEMail.Text.Length > 0)
                    {
                        if (txtFirstGuestEMail.Text.ToString().Contains("@") && txtFirstGuestEMail.Text.ToString().Contains(".") && txtFirstGuestName.Text.Length > 0)
                        {

                        }
                        else
                        {
                            lblValidate.Content = "Please Enter Valid EMail address and Name of First Guest";
                            return;
                        }
                    }
                    if (txtSecondGuestEMail.Text.Length > 0)
                    {
                        if (txtSecondGuestEMail.Text.ToString().Contains("@") && txtSecondGuestEMail.Text.ToString().Contains(".") && txtSecondGuestName.Text.Length > 0)
                        {
                        }
                        else
                        {
                            lblValidate.Content = "Please Enter Valid EMail address and Name of Second Guest";
                            return;
                        }
                    }
                    if (txtThiredGuestEMail.Text.Length > 0)
                    {
                        if (txtThiredGuestEMail.Text.ToString().Contains("@") && txtThiredGuestEMail.Text.ToString().Contains(".") && txtThiredGuestName.Text.Length > 0)
                        {
                        }
                        else
                        {
                            lblValidate.Content = "Please Enter Valid EMail address and Name of Thired Guest";
                            return;
                        }
                    }
                    if (txtFourthGuestEMail.Text.Length > 0)
                    {
                        if (txtFourthGuestEMail.Text.ToString().Contains("@") && txtFourthGuestEMail.Text.ToString().Contains(".") && txtFourthGuestName.Text.Length > 0)
                        {
                        }
                        else
                        {
                            lblValidate.Content = "Please Enter Valid EMail address and Name of Fourth Guest";
                            return;
                        }
                    }
                    if (txtFifthGuestEMail.Text.Length > 0)
                    {
                        if (txtFifthGuestEMail.Text.ToString().Contains("@") && txtFifthGuestEMail.Text.ToString().Contains(".") && txtFifthGuestName.Text.Length > 0)
                        {
                        }
                        else
                        {
                            lblValidate.Content = "Please Enter Valid EMail address and Name of Fifth Guest";
                            return;
                        }
                    }
                    if (txtSixthGuestEMail.Text.Length > 0)
                    {
                        if (txtSixthGuestEMail.Text.ToString().Contains("@") && txtSixthGuestEMail.Text.ToString().Contains(".") && txtSixthGuestName.Text.Length > 0)
                        {
                        }
                        else
                        {
                            lblValidate.Content = "Please Enter Valid EMail address and Name of Sixth Guest";
                            return;
                        }
                    }

                #endregion


                    System.Data.DataSet ds1 = ia.accid(txtEMail.Text);

                    if (UserInfo.MeetingID == "")
                    {
                        dsmeeting = ia.insmeetinginfo(txtEMail.Text,
                                  txtPassword.Password,
                                  txtFName.Text,
                                  txtLName.Text,
                                  txtCity.Text,
                                  txtPinCode.Text,
                                  txtPhone.Text,
                                  txtFax.Text,
                                  txtMeetingName.Text,
                                  txtMeetingDate.Text,
                                  CmbMeetingStart.SelectionBoxItem.ToString() + ":" + cmbMinStart.SelectionBoxItem.ToString(),
                                  CmbMeetingEnd.SelectionBoxItem.ToString() + ":" + cmbMinEnd.SelectionBoxItem.ToString(),
                                  ((ComboBoxItem)txtCountry.SelectedItem).Tag.ToString(),
                                  ((ComboBoxItem)txtState.SelectedItem).Tag.ToString(),
                                  txtFirstGuestEMail.Text,
                                  txtFirstGuestName.Text,
                                  txtSecondGuestEMail.Text,
                                  txtSecondGuestName.Text,
                                  txtThiredGuestEMail.Text,
                                  txtThiredGuestName.Text,
                                  txtFourthGuestEMail.Text,
                                  txtFourthGuestName.Text,
                                  txtFifthGuestEMail.Text,
                                  txtFifthGuestName.Text,
                                  txtSixthGuestEMail.Text,
                                  txtSixthGuestName.Text,
                                  ds1.Tables[0].Rows[0][0].ToString());
                        //MessageBox.Show(dsmeeting.Tables[0].Rows.Count.ToString());

                    }
                    else
                    {
                        bool bool1 = ia.delmeeting(int.Parse(UserInfo.MeetingID));

                        if (bool1)
                        {
                            dsmeeting = ia.insmeetinginfo(txtEMail.Text,
                            txtPassword.Password,
                            txtFName.Text,
                            txtLName.Text,
                            txtCity.Text,
                            txtPinCode.Text,
                            txtPhone.Text,
                            txtFax.Text,
                            txtMeetingName.Text,
                            txtMeetingDate.Text,
                            CmbMeetingStart.SelectionBoxItem.ToString() + ":" + cmbMinStart.SelectionBoxItem.ToString(),
                            CmbMeetingEnd.SelectionBoxItem.ToString() + ":" + cmbMinEnd.SelectionBoxItem.ToString(),
                           ((ComboBoxItem)txtCountry.SelectedItem).Tag.ToString(),
                           ((ComboBoxItem)txtState.SelectedItem).Tag.ToString(),
                            txtFirstGuestEMail.Text,
                            txtFirstGuestName.Text,
                            txtSecondGuestEMail.Text,
                            txtSecondGuestName.Text,
                            txtThiredGuestEMail.Text,
                            txtThiredGuestName.Text,
                            txtFourthGuestEMail.Text,
                            txtFourthGuestName.Text,
                            txtFifthGuestEMail.Text,
                            txtFifthGuestName.Text,
                            txtSixthGuestEMail.Text,
                            txtSixthGuestName.Text,
                            ds1.Tables[0].Rows[0][0].ToString()
                            );
                        }
                        UserInfo.MeetingID = "";
                    }

                    #region Body of EMail

                    StringBuilder ForHost = new StringBuilder();
                    StringBuilder ForGuest = new StringBuilder();
                    StringBuilder For1videoConference = new StringBuilder();

                    try
                    {
                        For1videoConference.Append("<b>User Query</b>");
                        For1videoConference.Append("<br>");
                        For1videoConference.Append("<br>");

                        For1videoConference.Append("<table>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("From:");
                        For1videoConference.Append(txtFName.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");
                        For1videoConference.Append("<br>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("From:");
                        For1videoConference.Append(txtLName.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");
                        For1videoConference.Append("<br>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("City:");
                        For1videoConference.Append(txtCity.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("State:");
                        For1videoConference.Append(txtState.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Country:");
                        For1videoConference.Append(txtCountry.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Phone:");
                        For1videoConference.Append(txtPhone.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Fax:");
                        For1videoConference.Append(txtFax.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Email:");
                        For1videoConference.Append(txtEMail.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("From:");
                        For1videoConference.Append(txtPassword.Password);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");
                        For1videoConference.Append("<br>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Preffered Date and Time");
                        For1videoConference.Append(txtMeetingDate.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("First Guest Email");
                        For1videoConference.Append(txtFirstGuestEMail.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Second Guest Email");
                        For1videoConference.Append(txtSecondGuestEMail.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Third Guest Email");
                        For1videoConference.Append(txtThiredGuestEMail.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Fourth Guest Email");
                        For1videoConference.Append(txtFourthGuestEMail.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Fifth Guest Email");
                        For1videoConference.Append(txtFifthGuestEMail.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");

                        For1videoConference.Append("<tr>");
                        For1videoConference.Append("<td width=100px>");
                        For1videoConference.Append("Sixth Guest Email");
                        For1videoConference.Append(txtSixthGuestEMail.Text);
                        For1videoConference.Append("</td>");
                        For1videoConference.Append("</tr>");


                        For1videoConference.Append("</table>");

                        ForHost.Append("You are now registered with 1videoConference (A rich web based Video Conferencing Solution)");
                        ForHost.Append("&nbsp;");
                        ForHost.Append("&nbsp;");
                        ForHost.Append("<br>");
                        ForHost.Append("<br>");

                        string encode = "mid=" + dsmeeting.Tables[0].Rows[0][0].ToString() + ",uname=" + txtFName.Text + ",role=Host";
                        hosturl = encodestring(encode);
                        ForHost.Append("You can take part in the meeting by following " + UserInfo.ConSiteURL + "?" + hosturl);


                        ForHost.Append("<br>");
                        ForHost.Append("<br>");

                        ForHost.Append("<br>");
                        ForHost.Append("<br>");

                        ForHost.Append("<table>");

                        ForHost.Append("<tr>");
                        ForHost.Append("<td><b>");
                        ForHost.Append("Login: </b>" + txtEMail.Text);
                        ForHost.Append("</td>");
                        ForHost.Append("</tr>");

                        ForHost.Append("<tr>");
                        ForHost.Append("<td><b>");
                        ForHost.Append("Password: </b>" + txtPassword.Password);
                        ForHost.Append("</td>");
                        ForHost.Append("</tr>");

                        ForHost.Append("<tr>");
                        ForHost.Append("<td><b>");
                        ForHost.Append("Subject: </b>" + txtMeetingName.Text);
                        ForHost.Append("</td>");
                        ForHost.Append("</tr>");

                        ForHost.Append("<tr>");
                        ForHost.Append("<td><b>");
                        ForHost.Append("Preferred Date: </b>" + txtMeetingDate.Text);
                        ForHost.Append("</td>");
                        ForHost.Append("</tr>");

                        ForHost.Append("<tr>");
                        ForHost.Append("<td><b>");
                        ForHost.Append("Start Time: </b>" + CmbMeetingStart.SelectionBoxItem.ToString() + ":" + cmbMinStart.SelectionBoxItem.ToString()); //+ " (Based On EST Time Zone)"
                        ForHost.Append("</td>");
                        ForHost.Append("</tr>");

                        ForHost.Append("<tr>");
                        ForHost.Append("<td><b>");
                        ForHost.Append("End Time: </b>" + CmbMeetingEnd.SelectionBoxItem.ToString() + ":" + cmbMinEnd.SelectionBoxItem.ToString()); // + " (Based On EST Time Zone)");
                        ForHost.Append("</td>");
                        ForHost.Append("</tr>");


                        if (txtFirstGuestEMail.Text.Length > 0)
                        {
                            ForHost.Append("<tr>");
                            ForHost.Append("<td valign=top><b>");
                            ForHost.Append("You have invited the following Guest: ");
                            ForHost.Append("</td>");
                            ForHost.Append("</tr>");
                            ForHost.Append("<tr>");
                            ForHost.Append("<td>");
                            ForHost.Append("<b>1: </b>" + txtFirstGuestEMail.Text + "<br>" + txtFirstGuestName.Text);
                            ForHost.Append("</td>");
                            ForHost.Append("</tr>");
                        }
                        else
                        {
                            ForHost.Append("</table>");
                        }

                        if (txtSecondGuestEMail.Text.Length > 0)
                        {
                            ForHost.Append("<tr>");
                            ForHost.Append("<td valign=top><b>");
                            ForHost.Append("<br>");
                            ForHost.Append("2: </b>" + txtSecondGuestEMail.Text + "<br>" + txtSecondGuestName.Text);
                            ForHost.Append("</td>");
                            ForHost.Append("</tr>");
                        }
                        else
                        {
                            ForHost.Append("</table>");
                        }

                        if (txtThiredGuestEMail.Text.Length > 0)
                        {
                            ForHost.Append("<tr>");
                            ForHost.Append("<td><b>");
                            ForHost.Append("<br>");
                            ForHost.Append("3: </b>" + txtThiredGuestEMail.Text + "<br>" + txtThiredGuestName.Text);
                            ForHost.Append("</td>");
                            ForHost.Append("</tr>");
                        }
                        else
                        {
                            ForHost.Append("</table>");
                        }

                        if (txtFourthGuestEMail.Text.Length > 0)
                        {
                            ForHost.Append("<tr>");
                            ForHost.Append("<td><b>");
                            ForHost.Append("<br>");
                            ForHost.Append("4: </b>" + txtFourthGuestEMail.Text + "<br>" + txtFourthGuestName.Text);
                            ForHost.Append("</td>");
                            ForHost.Append("</tr>");
                        }
                        else
                        {
                            ForHost.Append("</table>");
                        }

                        if (txtFifthGuestEMail.Text.Length > 0)
                        {
                            ForHost.Append("<tr>");
                            ForHost.Append("<td><b>");
                            ForHost.Append("<br>");
                            ForHost.Append("5: </b>" + txtFifthGuestEMail.Text + "<br>" + txtFifthGuestName.Text);
                            ForHost.Append("</td>");
                            ForHost.Append("</tr>");
                        }
                        else
                        {
                            ForHost.Append("</table>");
                        }

                        if (txtSixthGuestEMail.Text.Length > 0)
                        {
                            ForHost.Append("<tr>");
                            ForHost.Append("<td><b>");
                            ForHost.Append("<br>");
                            ForHost.Append("6: </b>" + txtSixthGuestEMail.Text + "<br>" + txtSixthGuestName.Text);
                            ForHost.Append("</td>");
                            ForHost.Append("</tr>");
                        }
                        else
                        {
                            ForHost.Append("</table>");
                        }

                        ForHost.Append("</table>");



                        ForGuest.Append("You have been invited by " + txtEMail.Text + " for attending a meeting ");
                        ForGuest.Append("&nbsp;");
                        ForGuest.Append("&nbsp;");
                        ForGuest.Append("<br>");
                        ForGuest.Append("<br>");


                        ForGuest.Append("<table>");

                        ForGuest.Append("<tr>");
                        ForGuest.Append("<td><b>");
                        ForGuest.Append("Subject: </b>" + txtMeetingName.Text);
                        ForGuest.Append("</td>");
                        ForGuest.Append("</tr>");

                        ForGuest.Append("<tr>");
                        ForGuest.Append("<td><b>");
                        ForGuest.Append("Preferred Date: </b>" + txtMeetingDate.Text);
                        ForGuest.Append("</td>");
                        ForGuest.Append("</tr>");

                        ForGuest.Append("<tr>");
                        ForGuest.Append("<td><b>");
                        ForGuest.Append("Start Time: </b>" + CmbMeetingStart.SelectionBoxItem.ToString() + ":" + cmbMinStart.SelectionBoxItem.ToString()); // + " (Based On EST Time Zone)");
                        ForGuest.Append("</td>");
                        ForGuest.Append("</tr>");

                        ForGuest.Append("<tr>");
                        ForGuest.Append("<td><b>");
                        ForGuest.Append("End Time: </b>" + CmbMeetingEnd.SelectionBoxItem.ToString() + ":" + cmbMinEnd.SelectionBoxItem.ToString()); //+ " (Based On EST Time Zone)");
                        ForGuest.Append("</td>");
                        ForGuest.Append("</tr>");

                        ForGuest.Append("<br>");
                        ForGuest.Append("<br>");
                        ForGuest.Append("</b> One Time Setup Instruction:-");
                        ForGuest.Append("&nbsp;");
                        ForGuest.Append("&nbsp;");
                        ForGuest.Append("<br>");
                        ForGuest.Append("<br>");


                        ForGuest.Append("Download and install 1videoConference Client SetUp from http://adiance.com/1VC/1VCClientSetup.exe");
                        ForGuest.Append("&nbsp;");
                        ForGuest.Append("&nbsp;");
                        ForGuest.Append("<br>");
                        ForGuest.Append("<br>");

                        if (txtFirstGuestEMail.Text.Length > 0)
                        {
                            StringBuilder userOne = new StringBuilder();
                            userOne.Append(ForGuest.ToString());

                            string encodestr = "mid=" + dsmeeting.Tables[0].Rows[0][0].ToString() + ",uname=" + txtFirstGuestEMail.Text + ",role=Participant";
                            string guesturl = encodestring(encodestr);
                            userOne.Append("Browse the URL " + UserInfo.ConSiteURL + "?" + guesturl + " and provide your E-Mail address to enter as Guest");
                            userOne.Append("&nbsp;");
                            userOne.Append("&nbsp;");
                            userOne.Append("<br>");
                            userOne.Append("<br>");
                            userOne.Append("</table>");
                            SendEmailTo(txtEMail.Text, txtFirstGuestEMail.Text, "1videoConference.com Video Conferencing Meeting Details", userOne.ToString());
                        }

                        if (txtSecondGuestEMail.Text.Length > 0)
                        {
                            StringBuilder userOne = new StringBuilder();
                            userOne.Append(ForGuest.ToString());

                            string encodestr = "mid=" + dsmeeting.Tables[0].Rows[0][0].ToString() + ",uname=" + txtSecondGuestEMail.Text + ",role=Participant";
                            string guesturl = encodestring(encodestr);
                            userOne.Append("Browse the URL " + UserInfo.ConSiteURL + "?" + guesturl + " and provide your E-Mail address to enter as Guest");
                            userOne.Append("&nbsp;");
                            userOne.Append("&nbsp;");
                            userOne.Append("<br>");
                            userOne.Append("<br>");
                            userOne.Append("</table>");
                            SendEmailTo(txtEMail.Text, txtSecondGuestEMail.Text, "1videoConference.com Video Conferencing Meeting Details", userOne.ToString());
                        }

                        if (txtThiredGuestEMail.Text.Length > 0)
                        {
                            StringBuilder userOne = new StringBuilder();
                            userOne.Append(ForGuest.ToString());

                            string encodestr = "mid=" + dsmeeting.Tables[0].Rows[0][0].ToString() + ",uname=" + txtThiredGuestEMail.Text + ",role=Participant";
                            string guesturl = encodestring(encodestr);
                            userOne.Append("Browse the URL " + UserInfo.ConSiteURL + "?" + guesturl + " and provide your E-Mail address to enter as Guest");
                            userOne.Append("&nbsp;");
                            userOne.Append("&nbsp;");
                            userOne.Append("<br>");
                            userOne.Append("<br>");
                            userOne.Append("</table>");
                            SendEmailTo(txtEMail.Text, txtThiredGuestEMail.Text, "1videoConference.com Video Conferencing Meeting Details", userOne.ToString());
                        }

                        if (txtFourthGuestEMail.Text.Length > 0)
                        {
                            StringBuilder userOne = new StringBuilder();
                            userOne.Append(ForGuest.ToString());

                            string encodestr = "mid=" + dsmeeting.Tables[0].Rows[0][0].ToString() + ",uname=" + txtFourthGuestEMail.Text + ",role=Participant";
                            string guesturl = encodestring(encodestr);
                            userOne.Append("Browse the URL " + UserInfo.ConSiteURL + "?" + guesturl + " and provide your E-Mail address to enter as Guest");
                            userOne.Append("&nbsp;");
                            userOne.Append("&nbsp;");
                            userOne.Append("<br>");
                            userOne.Append("<br>");
                            userOne.Append("</table>");
                            SendEmailTo(txtEMail.Text, txtFourthGuestEMail.Text, "1videoConference.com Video Conferencing Meeting Details", userOne.ToString());
                        }

                        if (txtFifthGuestEMail.Text.Length > 0)
                        {
                            StringBuilder userOne = new StringBuilder();
                            userOne.Append(ForGuest.ToString());

                            string encodestr = "mid=" + dsmeeting.Tables[0].Rows[0][0].ToString() + ",uname=" + txtFifthGuestEMail.Text + ",role=Participant";
                            string guesturl = encodestring(encodestr);
                            userOne.Append("Browse the URL " + UserInfo.ConSiteURL + "?" + guesturl + " and provide your E-Mail address to enter as Guest");
                            userOne.Append("&nbsp;");
                            userOne.Append("&nbsp;");
                            userOne.Append("<br>");
                            userOne.Append("<br>");
                            userOne.Append("</table>");
                            SendEmailTo(txtEMail.Text, txtFifthGuestEMail.Text, "1videoConference.com Video Conferencing Meeting Details", userOne.ToString());
                        }

                        if (txtSixthGuestEMail.Text.Length > 0)
                        {
                            StringBuilder userOne = new StringBuilder();
                            userOne.Append(ForGuest.ToString());

                            string encodestr = "mid=" + dsmeeting.Tables[0].Rows[0][0].ToString() + ",uname=" + txtSixthGuestEMail.Text + ",role=Participant";
                            string guesturl = encodestring(encodestr);
                            userOne.Append("Browse the URL " + UserInfo.ConSiteURL + "?" + guesturl + " and provide your E-Mail address to enter as Guest");
                            userOne.Append("&nbsp;");
                            userOne.Append("&nbsp;");
                            userOne.Append("<br>");
                            userOne.Append("<br>");
                            userOne.Append("</table>");
                            SendEmailTo(txtEMail.Text, txtSixthGuestEMail.Text, "1videoConference.com Video Conferencing Meeting Details", userOne.ToString());
                        }

                        SendEmailTo(UserInfo.ConSMTPUserName, txtEMail.Text, "1videoConference.com Video Conferencing Query ", ForHost.ToString());

                        MessageBox.Show("Meeting has been created successfully!!", "Meeting");
                        ((Canvas)((Grid)((InkCanvas)((InkCanvas)this.Parent).Parent).Parent).FindName("cnvMain")).IsEnabled = true;
                        ((Menu)((Grid)((InkCanvas)((InkCanvas)this.Parent).Parent).Parent).FindName("mnu")).IsEnabled = true;
                        ((InkCanvas)this.Parent).Children.Remove(this);
                        //NavigationService.GetNavigationService(this).Navigate(new Uri("LogOn.xaml", UriKind.RelativeOrAbsolute));

                    }
                    catch (SmtpException exp)
                    {
                        exp.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--SendingMail()--:----:--");
                        clsUtility.LogException = exp;
                        //MessageBox.Show(exp.Message.ToString());
                    }
                    #endregion
                }
                else
                {
                    lblValidate.Content = "Enter Valid EMail address";
                    return;
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--MeetingCreation()--:----:--");
                clsUtility.LogException = ex;
                //MessageBox.Show("CreateMeeting--:--CreateMeeting.xaml.cs--:-- Eneter() ---" + ex.Message); 
            }
        }

        public static void SendEmailTo(string from, string To, string Subject, string msg)
        {
            try
            {
                string SMTPSer = UserInfo.ConSMTPServer;
                string SMTPPo = UserInfo.ConSMTPPort;
                string SMTPUser = UserInfo.ConSMTPUserName;
                string SMTPPass = UserInfo.ConSMTPPassword;
                string SMTPssl = UserInfo.ConSMTPSSL;

                System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();
                mailMsg.From = new MailAddress(UserInfo.ConSMTPUserName);
                mailMsg.To.Add(To);

                mailMsg.Subject = Subject;
                mailMsg.SubjectEncoding = System.Text.Encoding.UTF8;

                mailMsg.Body = msg;
                mailMsg.BodyEncoding = System.Text.Encoding.UTF8;

                mailMsg.Priority = System.Net.Mail.MailPriority.High;

                mailMsg.IsBodyHtml = true;
                System.Net.Mail.SmtpClient SmtpMail = new System.Net.Mail.SmtpClient(SMTPSer, Convert.ToInt16(SMTPPo));
                SmtpMail.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPass);
                SmtpMail.EnableSsl = Convert.ToBoolean(SMTPssl);
                try
                {
                    SmtpMail.Send(mailMsg);
                }
                catch (Exception ex)
                {
                    ex.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--SendEmailTo()1--:----:--");
                    clsUtility.LogException = ex;
                    //MessageBox.Show(ex.Message.ToString());
                }
            }

            catch (Exception ex)
            {
                ex.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--SendEmailTo()2--:----:--");
                clsUtility.LogException = ex;
                //MessageBox.Show("CreateMeeting--:--CreateMeeting.xaml.cs--:-- SendEmailTo() ---" + ex.Message); 
            }
        }

        string encodestring(string str)
        {
            try
            {
                int j = 0;

                Byte[] encodedBytes = ASCIIEncoding.ASCII.GetBytes(str);
                Byte[] ans = new Byte[encodedBytes.Length];
                foreach (Byte b in encodedBytes)
                {

                    int i = Convert.ToInt32(b);

                    if ((i >= 65 && i <= 90) || (i >= 97 && i <= 122))
                    {
                        i += 4;
                        if ((i > 90 && i <= 97) || (i > 122 && i <= 129))
                            i = i - 26;

                    }
                    else if (i >= 48 && i <= 57)
                    {
                        i += 7;
                        if (i > 57)
                            i = i - 10;
                    }
                    else
                    {
                        if (i == 61)
                            i = 44;
                        else if (i == 44)
                            i = 61;
                    }

                    ans[j++] = Convert.ToByte(i);
                }
                return ASCIIEncoding.ASCII.GetString(ans);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "1videoConference--:--CreateMeeting.xaml.cs--:--encodestring()--:----:--");
                clsUtility.LogException = ex;
                //MessageBox.Show("CreateMeeting--:--CreateMeeting.xaml.cs--:-- encodestring() ---" + ex.Message);
                return null;
            }
        }

         public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);    
        }

         private void Dispose(bool disposing)
        {
            if(!this.disposed)
            {
                if(disposing)
                { 
                   
                }        
                disposed = true;

            }
        }

        ~CreateMeeting()
        {
            Dispose(false);
        }


    }
}